package com.example.servicearea.dahua;

import com.example.servicearea.lib.NetSDKLib;
import com.sun.jna.Pointer;

import java.util.HashMap;
import java.util.Map;

public  class VideoStatSumCallback implements NetSDKLib.fVideoStatSumCallBack{

    public Map<Long, PersonCapture> deviceInfoMap = new HashMap<>();



    private static VideoStatSumCallback instance = new VideoStatSumCallback();

    public static VideoStatSumCallback getInstance() {
        return instance;
    }


    public VideoStatSumCallback() {

    }

    public void setDeviceInfoMap(PersonCapture device) {
        deviceInfoMap.put(device.getStatHandle().longValue(), device);
    }


    public void invoke(NetSDKLib.LLong lAttachHandle, NetSDKLib.NET_VIDEOSTAT_SUMMARY stVideoState, int
            dwBufLen, Pointer dwUser){


        System.out.println("-------------------");
        PersonCapture device =deviceInfoMap.get(lAttachHandle.longValue());
        System.out.println("Received date from "+device.getDeviceIp());
        //        device.printInfo();
        System.out.printf("Channel[%d] GetTime[%s] RuleName[%s]\n" +
                        "People In Information[Total[%d] Hour[%d] Today[%d]]\n" +
                        "People Out Information[Total[%d] Hour[%d] Today[%d]]\n",
                stVideoState.nChannelID , stVideoState.stuTime.toStringTime() ,
                new String(stVideoState.szRuleName).trim(),
                stVideoState.stuEnteredSubtotal.nToday ,
                stVideoState.stuEnteredSubtotal.nHour ,
                stVideoState.stuEnteredSubtotal.nTotal ,
                stVideoState.stuExitedSubtotal.nToday ,
                stVideoState.stuExitedSubtotal.nHour ,
                stVideoState.stuExitedSubtotal.nTotal
        );
        device.savePersonData(stVideoState);
        System.out.println("-------------------");
    }

}